package com.seari.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.seari.bean.MessageBean;
import com.seari.bean.ResultCompanyBean;
import com.seari.service.DkfyResultService;
import com.seari.util.IData;

@Controller
@RequestMapping(value = "/dkfyResult")
public class DkfyResultController extends BaseController
{
	@Autowired
	private DkfyResultService dkfyResultService;
	
	/**
	 * @return
	 * @throws Exception
	 * 防疫整体说明
	 */
	@RequestMapping(value = "/fyOverallExplain")
	@ResponseBody
	public MessageBean<IData> fyOverallExplain() throws Exception {
		
		MessageBean<IData> msg = new MessageBean<IData>();
		List<IData> datas = dkfyResultService.fyOverallExplain(null);
		msg.setRows(datas);
		return msg;
	}
	/**
	 * @return
	 * @throws Exception
	 * 健康统计板块
	 */
	@RequestMapping(value = "/fyHealthStatistics")
	@ResponseBody
	public MessageBean<Integer> fyHealthStatistics() throws Exception 
	{
		
		MessageBean<Integer> msg = new MessageBean<Integer>();
		List<ResultCompanyBean> datas = dkfyResultService.fyResultCompany(null);
		List<Integer> ratioList = datas.stream().map(x -> x.getHealthratio()).collect(Collectors.toList());
		msg.setRows(ratioList);
		return msg;
	}
	
	/**
	 * @return
	 * @throws Exception
	 * 集团员工复工趋势
	 */
	@RequestMapping(value = "/fyWorkTrend")
	public String fyWorkTrend() throws Exception 
	{
		//不进行处理，重定向至dkyfController
		return "redirect:/dkfy/fyWorkTrend";
	}
	
	/**
	 * @return
	 * @throws Exception
	 * 员工复工及现场办公人数分布图
	 */
	@RequestMapping(value = "/radar")
	@ResponseBody
	public Map<String,Object> fecthRadarChartData() throws Exception 
	{
		List<ResultCompanyBean> datas = dkfyResultService.fyResultCompany(null);
		Map<String,Object> res = new HashMap<>();
		res.put("resWorkData",datas.stream().map(x -> x.getWorkPeople()).collect(Collectors.toList())); //复工人数
		res.put("localWorkData",datas.stream().map(x -> x.getWorkinsite()).collect(Collectors.toList())); //现场办公人数
		return res;
	}
	
	@RequestMapping(value = "/test")
	public String test() throws Exception 
	{
		return "redirect:/dkfyResult/fyHealthStatistics";
	}
}
